<template>
  <div class="comment-reply">
    <van-nav-bar :title="comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'">
      <van-icon
        slot="left"
        name="cross"
        color="#efa500"
        @click="$emit('close')"
      />
    </van-nav-bar>
    <div class="scroll-wrap">
      <!-- 当前评论项 -->
      <CommentItem :comment="comment" />
      <!-- /当前评论项 -->

      <!-- 评论回复列表 -->
      <van-cell title="全部回复" />
      <CommentList
        :list="commentList"
        :source="comment.com_id"
        type="c"
      />
    </div>
    <div class="post-warp">
      <van-button
        round
        size="small"
        class="post-btn"
        @click="isReplyComment = true"
      >评论</van-button>
    </div>
    <van-popup
      v-model="isReplyComment"
      position="bottom"
    >
      <CommentPost
        @post-success="onPostSuccess"
        :target="comment.com_id"
      />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '../comment-item/index.vue'
import CommentList from '../comment-list/index.vue'
import CommentPost from '../comment-post/index.vue'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isReplyComment: false,
      commentList: []
    }
  },
  computed: {},
  watch: {},
  created () { },
  methods: {
    onPostSuccess (data) {
      //  数量累加
      this.comment.reply_count++
      // 关闭弹框
      this.isReplyComment = false
      // 添加到顶部
      this.commentList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang='less'>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-warp {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
